# author = '李天宝'
# write in '2020/8/5 0005 16:56'

from rest_framework.views import APIView
from products.models import goods_category
from rest_framework.response import Response
from common.moexception import NoDataException

class CategoryGoods(APIView):
    """
    get
    category_id 分类的id号
    """
    def get(self,request):
        if 'category_id' not in request.query_params:
            NoDataException("要把category_id的参数传进来")
        category=goods_category.objects.filter(id=request.query_params['category_id'])
        #把这个分类下面的货物全部取出来，然后返回
        goods=category.goods.all()
        return Response({
            'code':200,
            'detail':goods.values('id','name','cover_img')
        })